<%= page_title "Merge other users into #{@user.name_and_email}" %>

Should be used when a user changed their login provider and created a new empty user in the process.
<br/>
Delete selected empty user and change #<%= @user.id %> <%= @user.name_and_email %> login credentials to that of the selected user.

<% if candidates = (User.where(email: @user.email) + (@user.name.present? ? User.where(name: @user.name) : []) - [@user]).uniq.presence %>
  <h2>Users with the same name or email</h2>
  <ul>
    <% candidates.each do |user| %>
      <li>ID <%= user.id %> <%= link_to user.name_and_email, user %>, last seen <%= user.last_seen_at&.to_fs(:db) || "Never" %></li>
    <% end %>
  </ul>
<% end %>

<%= form_for @user, url: user_user_merges_path(@user), method: :post do |f| %>
  <div class="form-group">
    <label class="col-lg-2 control-label">Destroy and take login credentials from user id</label>
    <div class="col-lg-4">
      <%= text_field_tag :merge_target_id, '', class: 'form-control' %>
    </div>
  </div>
  <br/>
  <br/>
  <%= f.actions label: 'Merge' %>
<% end %>
